public class School {
    private String schoolName;
    private List<Department> departments = new ArrayList<>();
    private List<Student> students = new ArrayList<>();
    public School(String schoolName) {
        this.schoolName = schoolName;
    }
    public void addStudent(Student student) {
        if (student == null) {
            throw new IllegalArgumentException("学生不可为空");
        }
        if (!students.contains(student)) {
            students.add(student);
        }
    }
    public String getSchoolName() {
        return schoolName;
    }
    public void setSchoolName(String schoolName) {
        this.schoolName = schoolName;
    }

public class Department {
    private List<Instructor> instructors = new ArrayList<>();
    private List<Subject> providedSubjects = new ArrayList<>();
        public void addInstructor(Instructor instructor) {
        if (!instructors.contains(instructor)) {
            instructors.add(instructor);
            instructor.setDepartment(this);
        }
    }
    public void addProvidedSubject(Subject subject) {
        if (!providedSubjects.contains(subject)) {
            providedSubjects.add(subject);
        }
    }
    
public class Instructor {
    private String instructorName;
    private List<Subject> taughtSubjects = new ArrayList<>();
    public Instructor(String instructorName) {
        this.instructorName = instructorName;
    }
    public void addTaughtSubject(Subject subject) {
        if (taughtSubjects.size() >= 3) {
            throw new IllegalStateException("教师最多只能教授3门课程");
        }
        if (!taughtSubjects.contains(subject)) {
            taughtSubjects.add(subject);
        }
    }
}

public class Student {
    private List<Subject> studiedSubjects = new ArrayList<>();
    public void addStudiedSubject(Subject subject) {
        if (studiedSubjects.size() >= 5) {
            throw new IllegalStateException("学生最多只能学习5门课程");
        }
        if (!studiedSubjects.contains(subject)) {
            studiedSubjects.add(subject);
        }
    }
    public List<Subject> getStudiedSubjects() {
        return new ArrayList<>(studiedSubjects);
    }
}


public class Subject {
    private String subjectName;
    public Subject(String subjectName) {
        this.subjectName = subjectName;
    }
    public String getSubjectName() {
        return subjectName;
    }
    public void setSubjectName(String subjectName) {
        this.subjectName = subjectName;
    }
}